﻿using BaseProject.Application.Interfaces;
using BaseProject.Domain.Models;

namespace BaseProject.Application.Implementation
{
    public class WebWorkContext : IWorkContext
    {
        private readonly IAuthenticationService _authenticationService;
        private User _cachedUser;

        public WebWorkContext(IAuthenticationService authenticationService)
        {
            this._authenticationService = authenticationService;
        }

        /// <summary>
        /// 当前用户信息
        /// </summary>
        public User CurrentUser
        {
            get
            {
                if (_cachedUser != null)
                    return _cachedUser;

                var user = _authenticationService.GetAuthenticatedUser();
                if (user != null)
                {
                    _cachedUser = user;
                }
                return _cachedUser;
            }
            set
            {
                _cachedUser = value;
            }
        }
    }
}